<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body></body>
  <script>
    // 递归：函数自己调用自己
    // 特点：类似于循环  必须有结束语句
    // function fn() {
    //     fn()
    // }
    // fn()
  </script>
  <script>
    function getNum(n) {
      if (n == 1) {
        return 1;
      } else {
        return n + getNum(n - 1);
      }
    }

    console.log(getNum(5));
    console.log(getNum(100));
    getNum(2);
    getNum(3);
    getNum(4);
    getNum(5);
  </script>
  <script>
    // 递归深拷贝
    var obj = {
      name: "zs",
      age: 18,
      object: {
        age: 20,
        aa: {
          age: 10,
        },
      },
      arr: [1, 2, 3],
    };
    var newObj = {};
    function recursion(obj, newObj) {
      for (key in obj) {
        if (obj[key].constructor == Object) {
          newObj[key] = {};
          recursion(obj[key], newObj[key]);
        } else if (obj[key].constructor == Array) {
          newObj[key] = [];
          recursion(obj[key], newObj[key]);
        } else {
          newObj[key] = obj[key];
        }
      }
    }
    recursion(obj, newObj);
    newObj.object.aa.age = 40;
    console.log(obj);
    console.log(newObj);
    var arr = [1];
    console.log(arr instanceof Object);
  </script>
</html>
